#!/usr/bin/python
# -*- coding: UTF-8 -*-
#cron:6 6,20 * * *
import json
import time
import random
import requests
import base64
import os
import sys
token=os.environ.get('hipc_token')
number = random.randint(200,1000)

# 加载通知服务
def load_send():
    cur_path = os.path.abspath(os.path.dirname(__file__))
    sys.path.append(cur_path)
    if os.path.exists(cur_path + "/notify2.py"):
        try:
            from notify2 import send
            return send
        except Exception as e:
            print(f"加载通知服务失败：{e}")
            return None
    else:
        print("加载通知服务失败")
        return None

def qiandao():
    headers = {
     'content-length':'68',
     'user-id':'41222',
     'xweb_xhr':'1',
     'platform':'miniprogram_windows',
     'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c11)XWEB/11437',
     'app':'hipc',
     'token':token,
     'content-type':'application/json',
     'accept':'*/*',
     'sec-fetch-site':'cross-site',
     'sec-fetch-mode':'cors',
     'sec-fetch-dest':'empty',
     'referer':'https://servicewechat.com/wx6265a35adb332603/180/page-frame.html',
     'accept-encoding':'gzip, deflate, br',
     'accept-language':'zh-CN,zh;q=0.9'}
    payload=base64.b64decode("eyJ1bml4dGltZSI6MTczMDM3MzkxMTAwMCwic2lnbiI6IkQyRTFGRTQ1RURFRkI3OEM4NEVENEJFRUM4MENDODQ2In0=")

    response0 = requests.request("POST", "https://api.hipcapi.com/v1/userscoreadd/signin", headers=headers, data=payload)
    a = response0.json()["message"]
    return a

def qianaotianshu():
    headers = {
        'content-length': '2',
        'user-id': '41222',
        'xweb_xhr': '1',
        'platform': 'miniprogram_windows',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c11)XWEB/11437',
        'app': 'hipc',
        'token': token,
        'content-type': 'application/json',
        'accept': '*/*',
        'sec-fetch-site': 'cross-site',
        'sec-fetch-mode': 'cors',
        'sec-fetch-dest': 'empty',
        'referer': 'https://servicewechat.com/wx6265a35adb332603/180/page-frame.html',
        'accept-encoding': 'gzip, deflate, br',
        'accept-language': 'zh-CN,zh;q=0.9'}
    payload = base64.b64decode("e30=")

    response0 = requests.request("POST", "https://api.hipcapi.com/v1/signin/get", headers=headers, data=payload)
    cishu = response0.json()["data"]["signin_log"]["continuous_day"]
    return cishu
    #print(data)

print(f'延迟{number}秒后开始')
time.sleep(number)
title = "HIPC签到通知"
contents = f'签到结果：{qiandao()},\n已连续签到：{qianaotianshu()}天。'
print(contents)
send_notify = load_send()
send_notify(title, contents)
# 将编码结果字典转换为JSON字符串
#data = json.dumps(encoded_results)

#print(data)
